home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / TEST / SHADE_TE.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  4.6 KB  |  140 lines

  1. /**
  2.  * This is an example of a program which uses the shade interactor. The
  3.  * point of the shade interactor is to show you how you can design and
  4.  * build new interactors for new interactions.
  5.  * @author Ian Smith
  6.  */
  7. package sub_arctic.test;
  8.  
  9. import sub_arctic.lib.*;
  10. import sub_arctic.input.*;
  11. import sub_arctic.anim.*;
  12. import sub_arctic.output.*;
  13. import sub_arctic.constraints.std_function;
  14.  
  15. import java.awt.Font;
  16.  
  17. public class shade_test extends debug_interactor_applet implements callback_object {
  18.   /**
  19.    * Initial font size
  20.    */
  21.   int font_size=12;
  22.   /**
  23.    * Labels on the toggles
  24.    */
  25.   String sizes[] = { "Eight Point", "Ten Point", "Twelve Point", 
  26.              "Fourteen Point"};
  27.   /**
  28.    * The maping to actual sizes
  29.    */
  30.   int point_sizes[] = {8, 10, 12, 14};
  31.   /**
  32.    * The collection of toggles
  33.    */
  34.   text_toggle_collection ttc;
  35.   /**
  36.    * The HTML text flow
  37.    */
  38.   text_flow flow;
  39.   /**
  40.    * Build the UI
  41.    */
  42.   public void build_ui(base_parent_interactor top) {
  43.     base_parent_interactor bpi;
  44.     button tmp;
  45.     label tlab;
  46.     /* build the shade */
  47.     shade s=new shade();
  48.     top.add_child(s);
  49.     /* shade will fill the whole applet */
  50.     s.set_x(0);
  51.     s.set_y(0);
  52.     s.set_w_constraint(std_function.offset(PARENT.X2(), 0));
  53.     s.set_h_constraint(std_function.offset(PARENT.Y2(), 0));
  54.     /* lets build a little UI to put in the shade */
  55.     /* we override this with constraints */
  56.     bpi=new base_parent_interactor(0,0,370,300); 
  57.     bpi.set_w_constraint(std_function.offset(PARENT.W(), 0));
  58.     bpi.set_h_constraint(std_function.offset(PARENT.H(), -40));
  59.     /* put a text flow in it */
  60.     flow=new text_flow(getParameter("TEXT"),350,300);
  61.     flow.set_w_constraint(std_function.offset(PARENT.W(), -20));
  62.     flow.set_h_constraint(std_function.offset(PARENT.H(), -35));
  63.     flow.set_x(10);
  64.     flow.set_y(15);
  65.     bpi.add_child(flow);
  66.     /* put some buttons below it */
  67.     tmp=new button("Back",null);
  68.     bpi.add_child(tmp);
  69.     tmp.set_x_constraint(std_function.eq(PREV_SIBLING.X()));
  70.     tmp.set_y_constraint(std_function.far_edge_just(PARENT.H(), 5));
  71.  
  72.     tmp=new button("Foward",null);
  73.     bpi.add_child(tmp);
  74.     tmp.set_x_constraint(std_function.offset(PREV_SIBLING.X2(), 5));
  75.     tmp.set_y_constraint(std_function.far_edge_just(PARENT.H(), 5));
  76.  
  77.     tmp=new button("Home",null);
  78.     bpi.add_child(tmp);
  79.     tmp.set_x_constraint(std_function.offset(PREV_SIBLING.X2(), 15));
  80.     tmp.set_y_constraint(std_function.far_edge_just(PARENT.H(), 5));
  81.     /* make this parent a child of the shade */
  82.     s.set_child(0,bpi);
  83.     /*
  84.      * Ok, now get ready for the second child of the shade (on
  85.      * top of the shade) 
  86.      */
  87.     bpi=new base_parent_interactor(0,0,100,200); // overriden width
  88.     bpi.set_w_constraint(std_function.offset(PARENT.W(),0));
  89.     /* put in a label */
  90.     tlab = new label("Reformat text as:", new Font("Helvetica",Font.BOLD,14));
  91.     tlab.set_x_constraint(std_function.centered(PARENT.W(), 0));
  92.     tlab.set_y_constraint(std_function.offset(PARENT.Y(), 50));
  93.     bpi.add_child(tlab);
  94.     /* make a set of toggles for the shade */
  95.     ttc=new text_toggle_collection(sizes,true,-1,this);
  96.     ttc.set_x_constraint(std_function.centered(PARENT.W(), 0));
  97.     ttc.set_y_constraint(std_function.offset(PREV_SIBLING.Y2(), 5));
  98.     /* put the toggles in place */
  99.     bpi.add_child(ttc);
  100.     /* we are initially at 12 point */
  101.     ttc.nth_toggle(2).set_cur_state(1);
  102.     /* make this bpi be the child of the shade in slot 1 */
  103.     s.set_child(1,bpi);
  104.   }
  105.   /**
  106.    * Handle a callback from the radio buttons.
  107.    */
  108.   public void callback(interactor from_obj,event evt, int callback_num,
  109.                Object callback_info) {
  110.  
  111.     Integer i=(Integer)callback_info;
  112.     int index=ttc.find_child(from_obj);
  113.     /* is it already that  size? */
  114.     if (point_sizes[index]==font_size) return;
  115.     /* it isn't the same size ... do it */
  116.     font_size=point_sizes[index];
  117.     /* set the size */
  118.     flow.set_font_size(font_size);
  119.     /* force a relayout */
  120.     flow.set_text(flow.text());
  121.   }
  122. }
  123.  
  124. /*=========================== COPYRIGHT NOTICE ===========================
  125.  
  126. This file is part of the subArctic user interface toolkit.
  127.  
  128. Copyright (c) 1996 Scott Hudson and Ian Smith
  129. All rights reserved.
  130.  
  131. The subArctic system is freely available for most uses under the terms
  132. and conditions described in 
  133.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  134. and appearing in full in the lib/interactor.java source file.
  135.  
  136. The current release and additional information about this software can be 
  137. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  138.  
  139. ========================================================================*/
  140.